class Solution:
    def findSubstring(self, s: str, words: list[str]) -> list[int]:
        from collections import defaultdict
        step = len(words[0])
        n = len(words)
        standard_length = n *step
        example= defaultdict(int)  # 用于判断该序列是不是一种组合方式
        for w in words:
            example[w] += 1
        

        def isValid(s):
            pair = [s[i:i+step] for i in range(0,len(s),step)]
            dicts = defaultdict(int)
            for c in pair:
                dicts[c] += 1
            return dicts == example

        result = []
        for i in range(0,len(s)-standard_length+1):
            strings = s[i:i+standard_length]
            if isValid(strings):
                result.append(i)
        return result
            

s = Solution()
print(s.findSubstring(s = "wordgoodgoodgoodbestword", words =["word","good","best","good"]))